/**
 * 针对 uni.request 做一个二次封装
 */

class RequestHttp {
	constructor() {

	}

	get<T>(url : string, params : object = {}) : Promise<T> {
		return uni.request({
			// @ts-ignore
			url: import.meta.env.VITE_API_BASE_URL + url,
			method: 'GET',
			data: params
		}).then(({ data }) => {
			// 直接将 接口返回值，给 resolve
			return (data as unknown as T)
		})
	}

	post<T>(url : string, params : object = {}): Promise<T> {
		return uni.request({
			// @ts-ignore
			url: import.meta.env.VITE_API_BASE_URL + url,
			method: "POST",
			data: params
		}).then(({ data }) => {
			// 直接将 接口返回值，给 resolve
			return (data as unknown as T)
		})
	}
}

export default new RequestHttp()